package com.fdb.efp.nls.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.nls.service.domain.NlsApplyLoanpay;
import com.fdb.efp.nls.service.facade.NlsApplyLoanpayService;
import com.fdb.efp.nls.service.vo.NlsApplyLoanpayVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.NlsApplyLoanpayDao;

/**
 * ServiceImpl: 放款申请信息
 * 
 * @author huangwb
 * @since 2018年12月27日 上午8:33:47
 * @version 1.0
 */
@Service("nlsApplyLoanpayService")
public class NlsApplyLoanpayServiceImpl implements NlsApplyLoanpayService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(NlsApplyLoanpayServiceImpl.class);
	private static final String CHANGE_DATA_ERROR = "数据转换出现异常，异常信息为：";
	@Autowired
	private NlsApplyLoanpayDao nlsApplyLoanpayDao;

	/**
	 * 新增操作
	 */
	@Override
	public int insertNlsApplyLoanpay(NlsApplyLoanpayVO inNlsApplyLoanpayVo) {
		logger.debug("当前新增数据为:" + inNlsApplyLoanpayVo.toString());
		int num = 0;
		try {
			NlsApplyLoanpay nlsApplyLoanpay = new NlsApplyLoanpay();
			beanCopy(inNlsApplyLoanpayVo, nlsApplyLoanpay);
			num = nlsApplyLoanpayDao.insertNlsApplyLoanpay(nlsApplyLoanpay);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	@Override
	public int deleteByPk(NlsApplyLoanpayVO inNlsApplyLoanpayVo) {
		logger.debug("当前删除数据条件为:" + inNlsApplyLoanpayVo);
		int num = 0;
		try {
			NlsApplyLoanpay nlsApplyLoanpay = new NlsApplyLoanpay();
			beanCopy(inNlsApplyLoanpayVo, nlsApplyLoanpay);
			num = nlsApplyLoanpayDao.deleteByPk(nlsApplyLoanpay);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inNlsApplyLoanpayVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	@Override
	public int updateByPk(NlsApplyLoanpayVO inNlsApplyLoanpayVo) {
		logger.debug("当前修改数据为:" + inNlsApplyLoanpayVo.toString());
		int num = 0;
		try {
			NlsApplyLoanpay nlsApplyLoanpay = new NlsApplyLoanpay();
			beanCopy(inNlsApplyLoanpayVo, nlsApplyLoanpay);
			num = nlsApplyLoanpayDao.updateByPk(nlsApplyLoanpay);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inNlsApplyLoanpayVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	@Override
	public NlsApplyLoanpayVO queryByPk(NlsApplyLoanpayVO inNlsApplyLoanpayVo) {

		logger.debug("当前查询参数信息为:" + inNlsApplyLoanpayVo);
		try {
			NlsApplyLoanpay queryNlsApplyLoanpay = new NlsApplyLoanpay();
			beanCopy(inNlsApplyLoanpayVo, queryNlsApplyLoanpay);
			NlsApplyLoanpay queryRslNlsApplyLoanpay = nlsApplyLoanpayDao.queryByPk(queryNlsApplyLoanpay);
			if (Objects.nonNull(queryRslNlsApplyLoanpay)) {
				NlsApplyLoanpayVO outNlsApplyLoanpayVo = beanCopy(queryRslNlsApplyLoanpay, new NlsApplyLoanpayVO());
				logger.debug("当前查询结果为:" + outNlsApplyLoanpayVo.toString());
				return outNlsApplyLoanpayVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<NlsApplyLoanpayVO> queryAllOwner(NlsApplyLoanpayVO nlsApplyLoanpayVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<NlsApplyLoanpayVO> list = null;
		try {
			List<NlsApplyLoanpay> nlsApplyLoanpays = nlsApplyLoanpayDao.queryAllOwnerByPage(nlsApplyLoanpayVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + nlsApplyLoanpays.size());
			pageSet(nlsApplyLoanpays, nlsApplyLoanpayVo);
			list = (List<NlsApplyLoanpayVO>) beansCopy(nlsApplyLoanpays, NlsApplyLoanpayVO.class);
		} catch (Exception e) {
			logger.error(CHANGE_DATA_ERROR, e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<NlsApplyLoanpayVO> queryAllCurrOrg(NlsApplyLoanpayVO nlsApplyLoanpayVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<NlsApplyLoanpay> nlsApplyLoanpays = nlsApplyLoanpayDao.queryAllCurrOrgByPage(nlsApplyLoanpayVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + nlsApplyLoanpays.size());
		List<NlsApplyLoanpayVO> list = null;
		try {
			pageSet(nlsApplyLoanpays, nlsApplyLoanpayVo);
			list = (List<NlsApplyLoanpayVO>) beansCopy(nlsApplyLoanpays, NlsApplyLoanpayVO.class);
		} catch (Exception e) {
			logger.error(CHANGE_DATA_ERROR, e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<NlsApplyLoanpayVO> queryAllCurrDownOrg(NlsApplyLoanpayVO nlsApplyLoanpayVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<NlsApplyLoanpay> nlsApplyLoanpays = nlsApplyLoanpayDao.queryAllCurrDownOrgByPage(nlsApplyLoanpayVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + nlsApplyLoanpays.size());
		List<NlsApplyLoanpayVO> list = null;
		try {
			pageSet(nlsApplyLoanpays, nlsApplyLoanpayVo);
			list = (List<NlsApplyLoanpayVO>) beansCopy(nlsApplyLoanpays, NlsApplyLoanpayVO.class);
		} catch (Exception e) {
			logger.error(CHANGE_DATA_ERROR, e);
		}

		return list;

	}

	/**
	 * 通过条件查询数据
	 * 
	 * @param nlsApplyLoanpayVo
	 * @return
	 * @author qiuyf
	 * @since 2019年1月2日 下午7:58:53
	 * @version 1.0
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<NlsApplyLoanpayVO> queryByCondition(NlsApplyLoanpayVO nlsApplyLoanpayVo) {
		logger.debug("通过条件查询列表数据开始......");
		NlsApplyLoanpay nlsApplyLoanpay = beanCopy(nlsApplyLoanpayVo, new NlsApplyLoanpay());
		List<NlsApplyLoanpayVO> result = null;
		try {
			List<NlsApplyLoanpay> list = nlsApplyLoanpayDao.queryByCondition(nlsApplyLoanpay);
			result = (List<NlsApplyLoanpayVO>) beansCopy(list, NlsApplyLoanpayVO.class);
		} catch (Exception e) {
			logger.error(CHANGE_DATA_ERROR + e.getMessage());
		}
		logger.debug("通过条件查询列表数据结束----------");
		return result;
	}

	/**
	 * 通过条件分页查询列表数据
	 * 
	 * @param nlsApplyLoanpayVo
	 * @return
	 * @author qiuyf
	 * @since 2019年1月15日 下午3:06:32
	 * @version 1.0
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<NlsApplyLoanpayVO> queryListByConditions(NlsApplyLoanpayVO nlsApplyLoanpayVo) {
		logger.debug("通过条件分页查询列表数据开始......");
		NlsApplyLoanpay nlsApplyLoanpay = beanCopy(nlsApplyLoanpayVo, new NlsApplyLoanpay());
		List<NlsApplyLoanpayVO> result = null;
		try {
			List<NlsApplyLoanpay> list = nlsApplyLoanpayDao.queryListsByPage(nlsApplyLoanpay);
			pageSet(list, nlsApplyLoanpay);
			result = (List<NlsApplyLoanpayVO>) beansCopy(list, NlsApplyLoanpayVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常，异常信息为：" + e.getMessage());
		}
		logger.debug("通过条件查询列表数据结束----------");
		return result;
	}

}
